package hiepst.solution;

import java.text.NumberFormat;
import java.util.Locale;

/**
 * Problem Statement
 * <P>
 * In documents, it is frequently necessary to write monetary amounts in a
 * standard format. We have decided to format amounts as follows: the amount
 * must start with '$' the amount should have a leading '0' if and only if it is
 * less then 1 dollar. the amount must end with a decimal point and exactly 2
 * following digits. the digits to the left of the decimal point must be
 * separated into groups of three by commas (a group of one or two digits may
 * appear on the left). Create a class FormatAmt that contains a method amount
 * that takes two int's, dollars and cents, as inputs and returns the properly
 * formatted String.<\P>
 * 
 * Definition<BR>
 * Class: FormatAmt<BR>
 * Method: amount<BR>
 * Parameters: int, int<BR>
 * Returns: String<BR>
 * Method signature: String amount(int dollars, int cents)<BR>
 * (be sure your method is public)<BR>
 * 
 * Limits<BR>
 * Time limit (s): 2.000<BR>
 * Memory limit (MB): 64<BR>
 * 
 * Notes<BR>
 * - One dollar is equal to 100 cents.<BR>
 * 
 * Constraints<BR>
 * - dollars will be between 0 and 2,000,000,000 inclusive<BR>
 * - cents will be between 0 and 99 inclusive<BR>
 * 
 * Examples<BR>
 * 
 * 0) 123456<BR>
 * 0<BR>
 * Returns: "$123,456.00"<BR>
 * Note that there is no space between the $ and the first digit.<BR>
 * 
 * 1)49734321<BR>
 * 9<BR>
 * Returns: "$49,734,321.09"<BR>
 * 
 * 2)0<BR>
 * 99<BR>
 * Returns: "$0.99"<BR>
 * Note the leading 0.<BR>
 * 
 * 3) 249<BR>
 * 30<BR>
 * Returns: "$249.30"<BR>
 * 
 * 4) 1000<BR>
 * 1<BR>
 * Returns: "$1,000.01"<BR>
 * 
 * <P>
 * This problem statement is the exclusive and proprietary property of TopCoder,
 * Inc. Any unauthorized use or reproduction of this information without the
 * prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003,
 * TopCoder, Inc. All rights reserved.<\P>
 * 
 * 
 * @author Hiep.Hong
 * 
 */
public class SRM149DIV2_FormatAmt {

	public String amount(int dollars, int cents) {
		return NumberFormat.getCurrencyInstance(Locale.US).format(
				dollars + cents / 100.0);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SRM149DIV2_FormatAmt formatAmt = new SRM149DIV2_FormatAmt();
		String amount = formatAmt.amount(123456, 0);
		System.out.println("amount = " + amount);

		amount = formatAmt.amount(49734321, 9);
		System.out.println("amount = " + amount);

		amount = formatAmt.amount(0, 99);
		System.out.println("amount = " + amount);

		amount = formatAmt.amount(249, 30);
		System.out.println("amount = " + amount);

		amount = formatAmt.amount(1000, 1);
		System.out.println("amount = " + amount);
	}

}
